package com.pc;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName DataService
 * @Description
 * @Author zhengyongbiao
 * @Date 2021/2/9
 * @Version 3.6.0
 * @Since JDK 1.8
 **/
public class Creeper {
    public static void main(String[] args) throws Exception {
        List<String> urls = new ArrayList<String>();
        urls.add("http://www.wxhouse.com/listsaleinfo?pro.icon=ecfed4145a39a24b04c8351693ec6c02&kstrr=9611eeebfab0a04371cbefdd3ab71e79");
        urls.add("http://www.wxhouse.com/listsaleinfo?pro.icon=ecfed4145a39a24b04c8351693ec6c02&kstrr=5de14058f2275244b4a6db0817268bf9");
        urls.add("http://www.wxhouse.com/listsaleinfo?pro.icon=ecfed4145a39a24b04c8351693ec6c02&kstrr=58758947c4733615c062266ffef6dfee");

        int chafeng = 0, daishou = 0, yishou = 0, zhongshu = 0, baoliu=0, diya = 0,yiyushou = 0;
        for (String url : urls) {
            Document document = Jsoup.connect(url).get();
            Elements elements = document.getElementsByClass("h30 dgray16px6");
            for (Element element : elements) {
                Elements chafengList = element.getElementsByAttributeValue("style", "background:#930");
                Elements diyaList = element.getElementsByAttributeValue("style", "background:#ccc");
                Elements daishouList = element.getElementsByAttributeValue("style", "background:#3f0");
                Elements yishouList = element.getElementsByClass("bg_sold");
                chafeng = chafeng + chafengList.size();
                diya = diya + diyaList.size();
                daishou = daishou + daishouList.size();
                yishou = yishou + yishouList.size();
                zhongshu = zhongshu +  element.children().get(0).children().size()-1;
            }
        }
        /*System.out.printf("查封:%s\r\n",chafeng);
        System.out.printf("抵押:%s\n",diya);
        System.out.printf("待售:%s\n",daishou);
        System.out.printf("网签:%s\n",yishou);
        System.out.printf("总套数:%s\n",zhongshu);*/
        System.out.printf("查封:%s，抵押:%s，待售:%s，网签:%s，总套数:%s",chafeng,diya,daishou,yishou,zhongshu);
    }
}
